package com.github.tangmonkmeat;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

/**
 * Description:
 *
 * @author zwl
 * @version 1.0
 * @date 2021/7/28 上午8:30
 */
public class 路径和 {

    public static void main(String[] args) {

        List<Integer> list = new ArrayList<>();

        list.add(1);

        List<Integer> list2 = new ArrayList<>(list.size());
        Collections.addAll(list2,new Integer[list.size()]);
        Collections.copy(list2,list);

        list.add(2);

        System.out.println("");

    }

    public boolean hasPathSum(TreeNode root, int targetSum) {
        if(root == null || targetSum == 0){
            return false;
        }
        return dfs(root,targetSum,root);
    }

    public boolean dfs(TreeNode root, int targetSum,TreeNode pre){
        if(root == null){
            return pre.left == null && pre.right == null && targetSum == 0;
        }
        return dfs(root.left,targetSum - root.val,root)
                || dfs(root.right,targetSum - root.val,root);
    }

    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {}

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }


}
